package CodingTest;

import java.util.List;

public class reverseList {
    public ListNode reverseList(ListNode pHead){
    ListNode pReverseHead = null;//反转过后的单链表存储头结点
    ListNode pNode = pHead;//定义pNode指向pHead
    ListNode pPrev = null;//定义存储前一个节点
    while(pNode != null){
        ListNode pNext = pNode.next;//定义pNext指向pNode的下一个节点
        if(pNext==null){//如果pNode的下一个节点为空，则Node即为结果
            pReverseHead =pNode;
        }
        pNode.next = pPrev;
        pPrev = pNode;
        pNode = pNext;
    }
    return pReverseHead;
     }

}
